#pragma once
#include <widgets/SPopupWindow.h>

#include "FindPasswordWebReq.h"
#include "FindPwdMobileVerifyDlg.h"
#include "FindPwdSuccessOverDlg.h"
#include "FindPwdUserInfoVerifyDlg.h"
class QLineEdit;
class SCheckEx;
class QGridLayout;
class QLabel;
class SLineEdit;
class SImage;
class FadeTips;
class QSpacerItem;
class FindPwdMobileVerifyDlg;
class QrAndLabelWidget;
class FindPwdChangePwdDlg;
class FindPwdSuccessOverDlg;
enum em_FindPasswordStep {
  step_Start_0 = 0,
  step_NoPass_1,   // 没验证过的手机
  step_Info_2,     // 没验证过手机信息
  step_FindPwd_3,  // 更改密码
  step_Over_4,     // 重置成功
  step_Max
};

class FindPasswordDlg : public SPopupWindow {
  Q_OBJECT
 public:
  FindPasswordDlg(QWidget* p = nullptr);

 protected:
  virtual void paintEvent(QPaintEvent* event) override;
  bool verifyGetMobileMessage();
  bool verifyMobileNumber(QString phoneNumber);
  bool verifyMobileCode();
  bool verifyGetCodeMessage();
  bool verifyUserInfo();
  bool verifyChangePwd();
  void beginMessageTimer();
  void enableButton(QPushButton* btn, bool enable, QString txt);
  void setVerifyCodeMsgReminder(bool success);
  void reEnableTimerButton();
  void setCodeMsgInfo();
  int getVerifyConfirm(int nACountState,
                       CFindPasswordMsg& pMsg);  // step0:"下一步"的验证
  void setVerifyCodeErrorTxt();
  void showErrorMsg(const QString& err);
  void hideFindPwdWidget(em_FindPasswordStep m_step, int nRespon);
  void setStep(em_FindPasswordStep step);
  void clearReminderMessage();
  void submitUserInfo();                          // step1:"下一步"的验证
  bool loadUserInfoMsg(CFindPasswordMsg& pMsg);   // 加载用户信息数据
  bool loadChangePwdMsg(CFindPasswordMsg& pMsg);  // 加载修改密码数据
  void setAccountName();
  void submitChangePassword();

 Q_SIGNALS:
  void clearStartPwd();

 protected slots:
  void onCloseBtn();
  void onGetCode();
  void onNextStep();
  void onCountDown();
  void onWebReqMsg();
  void onReLogin();

 private:
  QVBoxLayout* m_mainLayout = nullptr;
  QTimer* m_timeCountdown = nullptr;
  QSpacerItem* m_spVItem = nullptr;
  QPushButton* m_nextStepButton = nullptr;
  QPushButton* m_cancelButton = nullptr;
  QString m_mobileMsg = "";  // 找回密码错误信息提示
  QString m_codeMsg = "";
  QString m_reminderMsg = "";
  QString m_mobileNumber = "";
  QString m_codeNumber = "";
  QString m_noPassMsg = "";
  QString m_userInfoMsg = "";  // 验证个人信息错误信息提示
  QString m_accountName = "";
  QString m_changePwdMsg = "";
  int m_nMessageTime;  // 验证码计时
  CFindPasswordWebReq m_webReq;
  FadeTips* m_errTips = nullptr;
  std::map<QString, CFindPasswordMsg> m_mapState;  // 获取成功的手机状态会保存
  em_FindPasswordStep m_step = step_Start_0;
  FindPwdMobileVerifyDlg* m_findPwdMobileVerifyDlg = nullptr;  // step_Start_0
  QrAndLabelWidget* m_qrCodeAndLabel = nullptr;  // step_NoPass_1 没验证过的手机
  FindPwdUserInfoVerifyDlg* m_findPwdUserInfoDlg =
      nullptr;  // step_Info_2	 没验证过手机信息
  FindPwdChangePwdDlg* m_findPwdChangePwdDlg =
      nullptr;  // step_FindPwd_3 更改密码
  FindPwdSuccessOverDlg* m_findPwdSuccessOverDlg =
      nullptr;  // step_Over_4    重置成功
};
